package com.lagou.dao;

import com.lagou.io.Resources;
import com.lagou.pojo.User;
import com.lagou.sqlSession.SqlSession;
import com.lagou.sqlSession.SqlSessionFactory;
import com.lagou.sqlSession.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class Userdaoimpl implements IUserdao {
    public User findByCondition(User user) throws Exception {
        InputStream resourceAsSteam = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory build = SqlSessionFactoryBuilder.build(resourceAsSteam);
        SqlSession sqlSession = build.OpenSession();

        Object o = sqlSession.selectOne("user.selectList", user);
        return (User) o;
    }

    public List<User> findAll() throws Exception {
        InputStream resourceAsSteam = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory build = SqlSessionFactoryBuilder.build(resourceAsSteam);
        SqlSession sqlSession = build.OpenSession();
        List<User> objects = sqlSession.selectList("user.selectList");
        return objects;
    }

    public int deleteById(User user) throws Exception {
    return 0;
    }

    public int updateById(User user) throws Exception {
        return 0;

    }

    public int addUser(User user) throws Exception {
        return 0;
    }

}
